#ifndef vertexbuffer_directx9_h__
#define vertexbuffer_directx9_h__
#include <d3d9.h>
#include "../ivertexbuffer.h"
#include "math/vertex.h"

namespace gecko
{

class IRenderer;
class IIndexBuffer;

class VertexBuffer_DirectX9 : public IVertexBuffer
{
public:
	// destructor
	virtual ~VertexBuffer_DirectX9();

	// Initialise the vertex buffer.
	bool Initialise(IRenderer *r, unsigned int vertexCount, bool dynamic);

	// Lock the buffer prior to accessing vertex data.
	bool Lock(unsigned int offset, unsigned int vertexCount, Vertex** verts);

	// Unlock the buffer after accessing vertex data.
	bool Unlock();

	// Destroy the buffer and release resources.
	bool Destroy();

	// Set the index buffer used to render.
	bool SetIndexBuffer(IIndexBuffer *ib);

	// Render the geometry.
	bool Render(ePrimitiveType primitiveType, unsigned int primitiveCount);

	// Render the geometry with an index buffer set.
	bool RenderIndexed(ePrimitiveType primitiveType, unsigned int indexCount, unsigned int primitiveCount);

public:
    LPDIRECT3DVERTEXBUFFER9 m_pVB;

private:
	// private constructor
	VertexBuffer_DirectX9();

	bool                            m_dynamic;
    unsigned int                    m_vertexCount;
    LPDIRECT3DVERTEXDECLARATION9    m_vertexDeclaration;
    bool                            m_isSetup;
    bool                            m_indexBufferSet;
    LPDIRECT3DDEVICE9               m_d3dDevice;

	// allow renderer to new this up
	friend class Renderer_DirectX9;
};

}// namespace gecko

#endif // vertexbuffer_directx9_h__